using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.VisualStudio.DebuggerVisualizers;
using Microsoft.SharePoint;

namespace SPDV
{
    public class SPWebObjectProvider : VisualizerObjectSource
    {
        public override void GetData(object target, System.IO.Stream outgoingData)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(outgoingData, GetSerializableObject((SPWeb)target));
        }
        private SPWebData GetSerializableObject(SPWeb web)
        {
            SPWebData wd = new SPWebData();
            wd.ServerRelativeUrl = web.ServerRelativeUrl;
            wd.Title = web.Title;
            wd.ID = web.ID;
            wd.Url = web.Url;
            wd.Name = web.Name;
            wd.IsRootWeb = web.IsRootWeb;
            wd.HasUniqueRoleDefinitions = web.HasUniqueRoleDefinitions;
            wd.HasUniqueRoleAssignments = web.HasUniqueRoleAssignments;
            wd.Description = web.Description;
            wd.WebTemplate = web.WebTemplate;
            foreach (SPWeb w in web.Webs)
            {
                wd.Webs.Add(GetSerializableObject(w));
                w.Dispose();
            }
            return wd;
        }
    }
}
